package cn.bugstack.domain.activity.service.discount.Impl;

import cn.bugstack.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.bugstack.domain.activity.service.discount.AbstractDiscountCalculateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("ZJ")
@Slf4j
public class ZJCalculateService extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupByDiscount) {
        String marketExpr = groupByDiscount.getMarketExpr();
        if(originalPrice.compareTo(BigDecimal.ZERO) < 0){
            return originalPrice;
        }

        BigDecimal deductionPrice = originalPrice.subtract(new BigDecimal(marketExpr));

        if(deductionPrice.compareTo(BigDecimal.ZERO) <=0){
            return new BigDecimal("0.01");
        }
        return deductionPrice;
    }
}
